// Copyright (c) 2025, 大连理工大学 (Dalian University of Technology)
//
// Licensed under the Mulan PSL v2.
// You can use this file according to the terms and conditions of the Mulan PSL v2.
// You may obtain a copy of the License at
//
//     http://license.coscl.org.cn/MulanPSL2
//
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
// EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. SEE THE MULAN PSL v2
// FOR MORE DETAILS.

#include "Import/BDFImport/BulkData/Property/PBRSECTParser.h"
#include "Import/BDFImport/BulkData/Partition/SET1Parser.h"

#include "gtest/gtest.h"

#include "DataStructure/Common/Constant.h"

#include "DBManager/DBServiceFactory.h"
#include "DBManager/IService/Input/Property/IPBRSECTService.h"

#include "Import/BDFImport/BulkData/Node/PointParser.h"
using SG::DataStructure::Common::TOLERANCE;
using namespace SG::DataStructure::FEM;
#include "Import/BDFImport/BDFParserBase.h"
using namespace SG::DBManager;
using namespace SG::Import;
extern std::shared_ptr<DBServiceFactory> DB_SERVICEFACTORY;
extern std::vector<std::string>          dividedEntryInfo;

class PBRSECTParserTest : public ::testing::Test
{
  public:
    static void SetUpTestSuite ()
    {
        DB_SERVICEFACTORY->ClearDatabase ();

        std::vector<std::string> Entry0 = { "POINT   111             0.0     0.0   " };
        BDF::divideBulkEntry (Entry0, dividedEntryInfo);
        SG::Import::BDF::BULKDATA::ParsePOINT (DB_SERVICEFACTORY, dividedEntryInfo);

        std::vector<std::string> Entry1 = { "POINT   112             20.0    0.0    " };
        BDF::divideBulkEntry (Entry1, dividedEntryInfo);
        SG::Import::BDF::BULKDATA::ParsePOINT (DB_SERVICEFACTORY, dividedEntryInfo);

        std::vector<std::string> Entry2 = { "POINT   113             20.0    19.4  " };
        BDF::divideBulkEntry (Entry2, dividedEntryInfo);
        SG::Import::BDF::BULKDATA::ParsePOINT (DB_SERVICEFACTORY, dividedEntryInfo);

        std::vector<std::string> Entry3 = { "POINT   114             0.0     19.4 " };
        BDF::divideBulkEntry (Entry3, dividedEntryInfo);
        SG::Import::BDF::BULKDATA::ParsePOINT (DB_SERVICEFACTORY, dividedEntryInfo);

        std::vector<std::string> Entry4 = { "SET1    111     111     THRU    114 " };
        BDF::divideBulkEntry (Entry4, dividedEntryInfo);
        SG::Import::BDF::BULKDATA::ParseSET1 (DB_SERVICEFACTORY, dividedEntryInfo);

        std::vector<std::string> Entry5 = { "SET1    122     111     112" };
        BDF::divideBulkEntry (Entry5, dividedEntryInfo);
        SG::Import::BDF::BULKDATA::ParseSET1 (DB_SERVICEFACTORY, dividedEntryInfo);

        std::vector<std::string> Entry6 = { "SET1    133     113     114     113" };
        BDF::divideBulkEntry (Entry6, dividedEntryInfo);
        SG::Import::BDF::BULKDATA::ParseSET1 (DB_SERVICEFACTORY, dividedEntryInfo);

        std::vector<std::string> Entry10 = { "pbrsect  31     10      GS           ", "        OUTP=111,inp=122,inp=133" };
        BDF::divideBulkEntry (Entry10, dividedEntryInfo);
        SG::Import::BDF::BULKDATA::ParsePBRSECT (DB_SERVICEFACTORY, dividedEntryInfo);
    }
};

TEST_F (PBRSECTParserTest, ParseEntrySeg10)
{
    PBRSECTData data;
    DB_SERVICEFACTORY->get<IPBRSECTService> ()->FindById (31, data);

    ASSERT_TRUE (data.m_id == 31);
    ASSERT_TRUE (data.m_MID == 10);
    ASSERT_TRUE (data.m_FORM == 1);

    ASSERT_TRUE (data.m_sections.size() == 1);

    ASSERT_NEAR (data.m_sections[0].OHEIGHT, 19.4, SG::DataStructure::Common::TOLERANCE);
    ASSERT_NEAR (data.m_sections[0].OWIDTH, 20.0, SG::DataStructure::Common::TOLERANCE);

    ASSERT_TRUE (data.m_sections[0].ings.size() == 0);
    ASSERT_TRUE (data.m_sections[0].inps.size() == 2);

    SG::DataStructure::FEM::BeamSectionArbitrary outData;
    DB_SERVICEFACTORY->get<IPBRSECTService> ()->ConvertToBeamSectionArbitrary (31, outData);
    ASSERT_TRUE (outData.m_id == 31);
    ASSERT_TRUE (outData.m_outer.size() == 4);
    ASSERT_TRUE (outData.m_holes.size() == 2);
    ASSERT_TRUE (outData.m_holes[0].size() == 2);



}
